
from rest_framework import serializers
from book.models import BookInfo

class PeopleRelatedSerializer(serializers.Serializer):

    id=serializers.IntegerField()
    name=serializers.CharField()
    password=serializers.CharField()

class BookInfoSerializers(serializers.Serializer):
    """图书数据序列化器具"""
    id = serializers.IntegerField()
    name = serializers.CharField()
    pub_date = serializers.DateField()
    readcount = serializers.IntegerField()

    people = PeopleRelatedSerializer(many=True)

    """
    {'id': 1, 'name': '射雕英雄传', 'pub_date': '1980-05-01', 'readcount': 12, 
    'people': 
    [OrderedDict([('id', 1), ('name', '郭靖'), ('passwor3456abc')]), 
    OrderedDict([('id', 2), ('name', '黄蓉'), ('password', '123456abc')]), 
    OrderedDict([('id', 3), ('name', '黄药师'), ('passwor123456abc')]), 
    OrderedDict([('id', 4), ('name', '欧阳锋'), ('password', '123456abc')]), 
    OrderedDict([('id', 5), ('name', '梅超风'), ('pas, '123456abc')])
    ]
    }

    """




class PeopleInfoSerializers(serializers.Serializer):
    id = serializers.IntegerField()
    name = serializers.CharField()
    password = serializers.CharField()
    description = serializers.CharField()
    is_delete = serializers.BooleanField()

    # 外键的两种书写
    # book_id = serializers.IntegerField()
    # queryset 告知系统在哪里匹配外键  read_onle 即只读不验证数据
    # book = serializers.PrimaryKeyRelatedField(queryset=BookInfo.objects.all())
    # book = serializers.PrimaryKeyRelatedField(read_only=True)
    # 获取关联外键的字符串信息
    # book =serializers.StringRelatedField()
    # 获取管理啊外键模型的所有信息
    # book = BookInfoSerializers()

    """
    ①book:1                             PrimaryKeyRelationField                                                       

    ②book_id:1                          IntergerField

    ③book:射雕英雄传                      StringRelationField

    ④book: {id:1,name:射雕英雄传,readcount:10}   BookInfoSerializer

    """


